//
//  FSReadRecordController_Second.m
//  Trade
//
//  Created by 刘沿 on 16/4/12.
//  Copyright © 2016年 刘沿. All rights reserved.
//

#import "FSReadRecordController_Second.h"
#import "GDataDefines.h"

@interface FSReadRecordController_Second ()

@property(nonatomic,copy)NSString * readinfo;


@end

@implementation FSReadRecordController_Second

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"阅读记录";

    [self loadData];
    
}

-(void)loadData{
    [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray * array = @[@{@"unId":self.fileId},@{@"userId":userId}];
    [HttpTools postWithURL:KexchgeneralURL arrays:array method:KlookRecordMethod success:^(id JSON) {
        [MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:YES];
        [self getDataFromXml:JSON];
    } failure:^(NSError *error) {
        [MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:YES];
    }];
}

-(void)getDataFromXml:(id)json{
    NSData * data = [json dataUsingEncoding:NSUTF8StringEncoding];
    GDataXMLDocument *xmlDocument = [[GDataXMLDocument alloc] initWithData: data options:0 error:nil];
    //获取根节点
    GDataXMLElement *rootElement = [xmlDocument rootElement];
    //获取根节点下的节点
    NSArray *rootData= [rootElement elementsForName:@"数据"];
    for (GDataXMLElement *subElement in rootData) {
        NSArray *tempData = [subElement elementsForName:@"数据要素"];
        for (GDataXMLElement *data in tempData) {
            GDataXMLElement * fileNumElement = [[data elementsForName:@"readinfo"] objectAtIndex:0];
            self.readinfo = [fileNumElement stringValue];
        }
    }
    
    [self.tableView reloadData];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}

#pragma mark UITbableViewCell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * cellIdentifier = @"cellIdentifier";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell ==nil) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    cell.textLabel.text = self.readinfo;
    cell.textLabel.numberOfLines = 0;
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    return cell;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return [FSHightTool heightbyString:self.readinfo font:14 minsWidth:38] +40;
}


@end
